/*
 * Created on 2005-7-6
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.sohu.sip.auth.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sohu.peak.util.Logger;
import com.sohu.sip.auth.business.bean.UserActorBean;
import com.sohu.sip.auth.business.event.UserActorAddEvent;
import com.sohu.sip.auth.business.event.UserActorListEvent;
import com.sohu.sip.auth.business.result.UserActorAddResult;
import com.sohu.sip.auth.business.result.UserActorListResult;
import com.sohu.sip.auth.constant.AuthConstant;
import com.sohu.sip.auth.util.ParamUtil;

/**
 * @author luciali
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class UserActorAction extends BaseAction {
	private static Logger log = new Logger();
	
	public String insertUserActor() {
		try {
			HttpServletRequest request=org.apache.struts2.ServletActionContext.getRequest();
			HttpServletResponse response=org.apache.struts2.ServletActionContext.getResponse();
			UserActorAddEvent event = new UserActorAddEvent(ParamUtil.getLong(request, "userId").longValue(),
					(String[])request.getParameterValues("actors"));
			UserActorAddResult result = UserActorBean.getInstance().addUserActors(event);
			request.setAttribute("result", result);

			if (result.getStatus() == 0) {
				//response.sendRedirect("useractor_success.sip");
				return  "success";
			} else {
				return "failure";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "failure";
		}
	}

	public String listUserActor() {
		try {
			HttpServletRequest request=org.apache.struts2.ServletActionContext.getRequest();
			//HttpServletResponse response=org.apache.struts2.ServletActionContext.getResponse();
			UserActorListEvent event = new UserActorListEvent(-1,
					ParamUtil.getLong(request, "actorId").longValue(),
					ParamUtil.getInt(request, "pagination.pageNO", 1).intValue(),
					ParamUtil.getInt(request, "pageCount", AuthConstant.COUNT_PERPAGE).intValue());
			UserActorListResult result = UserActorBean.getInstance().list(event);
			request.setAttribute("result", result);
			request.setAttribute("pagination", result.getPagination());
			if (result.getStatus() == 0)
				return "listUserActor";
			else
				return "failure";
		} catch (Exception e) {
			log.error(e);
			return "failure";
		}
	}

	public String listUserActor2() {
		try {
			HttpServletRequest request=org.apache.struts2.ServletActionContext.getRequest();
			//HttpServletResponse response=org.apache.struts2.ServletActionContext.getResponse();
			UserActorListEvent event = new UserActorListEvent(ParamUtil.getLong(request, "userId").longValue(),
					-1,
					ParamUtil.getInt(request, "pagination.pageNO", 1).intValue(),
					ParamUtil.getInt(request, "pageCount", AuthConstant.COUNT_PERPAGE).intValue());
			UserActorListResult result = UserActorBean.getInstance().list(event);
			request.setAttribute("result", result);
			request.setAttribute("pagination", result.getPagination());
			if (result.getStatus() == 0)
				return "listUserActor2";
			else
				return "failure";
		} catch (Exception e) {
			log.error(e);
			return "failure";
		}
	}

	public String success() {
		
		return "success";
	}

	public String failure() {
		return "failure";
	}		

}
